﻿function RendPageNavigator(data,divID,onclickFunc)
{
    var domDiv = $get(divID);
    if(domDiv!=null)
    {
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        }
        if(data.pageCount<2)
        {
             Sys.UI.DomElement.addCssClass(domDiv, "DisplayNone");
             domDiv.innerHTML = "";
             return;
        }
        var re=/\{0\}/gi;
        var re1=/\{1\}/gi;                  
        var strSelect = "<span class='page_select'>{0}</span>&nbsp;";
        var strUnSelect = "<span class='page_none grey10'><a href='javascript:void (0)' onclick='{1}({0})'>{0}</a></span>&nbsp;";
        var strOther = "<span class='page_none grey10'><a href='javascript:void (0)' onclick='{1}({0})'>...</a></span>&nbsp;";
        
        
        var index = data.PageIndex - 4;
        var end = data.PageIndex+5;
        if(index<1) index = 1;                                        
        if(end>data.pageCount) end = data.pageCount;
        if(end-index<9)
        {
            if(index>1) 
            {
                index = end-9;
                if(index<1) index = 1;
            }
            else if(end<data.pageCount)
            {
                end = index+9;
                if(end>data.pageCount) end = data.pageCount;
            }
        }
        var listBuilder = new Sys.StringBuilder();
        if(index>1) listBuilder.append(strOther.replace(re, index-1).replace(re1, onclickFunc));
        for (;index< end+1; ++index) 
        {
            if(index==data.PageIndex)
            {
                listBuilder.append(strSelect.replace(re, index));
            }
            else
            {
                listBuilder.append(strUnSelect.replace(re, index).replace(re1, onclickFunc));
            }
        }
        if(end<data.pageCount) listBuilder.append(strOther.replace(re, end+1).replace(re1, onclickFunc));
        domDiv.innerHTML = listBuilder.toString();
    }
}

function RendPage(data,divID,sHome,sPre,sLast,sNext,sSel,sUnSel)
{
    var domDiv = $get(divID);
    if(domDiv!=null)
    {
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        }
        if(data.pageCount<2)
        {
             Sys.UI.DomElement.addCssClass(domDiv, "DisplayNone");
             domDiv.innerHTML = "";
             return;
        }
        var re=/\$I\$/gi;
        
        var index = data.PageIndex - 4;
        var end = data.PageIndex+5;
        if(index<1) index = 1;                                        
        if(end>data.pageCount) end = data.pageCount;
        if(end-index<9)
        {
            if(index>1) 
            {
                index = end-9;
                if(index<1) index = 1;
            }
            else if(end<data.pageCount)
            {
                end = index+9;
                if(end>data.pageCount) end = data.pageCount;
            }
        }
        var listBuilder = new Sys.StringBuilder();
        if(index>1)
        {
            listBuilder.append(sHome);
            listBuilder.append(sPre.replace(re, data.PageIndex-1));
        }
        for (;index< end+1; ++index) 
        {
            if(index==data.PageIndex)
            {
                listBuilder.append(sSel.replace(re, index));
            }
            else
            {
                listBuilder.append(sUnSel.replace(re, index));
            }
        }
        if(end<data.pageCount) 
        {
            listBuilder.append(sNext.replace(re, data.PageIndex+1));
            listBuilder.append(sLast);
        }
        domDiv.innerHTML = listBuilder.toString();
    }
}

function GetLanguageLabel(selid,value)
{
    var domDiv = $get(selid);
    if(domDiv!=null)
    {
        for (var index = 0; index < domDiv.options.length; ++index) 
        {
            if(domDiv.options[index].value.toLowerCase()==value.toLowerCase())
            {
                return domDiv.options[index].text;
                break;
            }
        }
    }
    return value;
}
function showProgressBar(visible) 
{
    if($get("progress")==null)
    {
	var oDiv;
        try{oDiv = document.createElement("<div>")}catch(e){oDiv = document.createElement("div")};
        oDiv.id = "progress";
        var text;
		if(typeof(loading) != "undefined")
		{
			text = document.createTextNode(loading);
		}
		else
		{
			text = document.createTextNode("Loading...");
		}
        oDiv.appendChild(text);
        document.body.appendChild(oDiv);
        Sys.UI.DomElement.addCssClass($get("progress"), "progressCss");
    }
    
    if(visible)
    {
        $create(AjaxControlToolkit.AlwaysVisibleControlBehavior, 
        {"HorizontalOffset":0,"HorizontalSide":0,"VerticalOffset":0,"VerticalSide":0,"id":"avce"}, null, null, $get("progress"));
    }
    else
    {
        var cmp = $find("avce");
        if(cmp!=null) cmp.dispose();
    }
    $get("progress").style.display = visible ? "block" : "none";
}
function show(domid,visible)
{
    var e = domid;
    if (typeof domid == 'string')
    {
        e = $get(domid);
    }
    if (!e) return;
    if (visible != GetVisible(e)) {
        
        if (visible) 
        {
            if (e.style.removeAttribute) 
            {
                e.style.removeAttribute("display");
            } 
            else 
            {
               e.style.removeProperty("display");
            }
        }
        else 
        {
            e.style.display = 'none';
        }
        e.style.visibility = visible ? 'visible' : 'hidden';
    }
}
google_ad_client = "pub-2873751441352197";
google_ad_width = 160;
google_ad_height = 600;
google_ad_format = "160x600_as";
google_ad_type = "text";
google_ad_channel = "";
google_color_border = "ffffff";
google_color_bg = "ffffff";
google_color_link = "336699";
google_color_text = "000000";
google_color_url = "008000";
function CreateGoogle(w,h,f,t,ch,c1,c2,c3,c4,c5)
{
    if(w!=null)google_ad_width = w;
    if(h!=null)google_ad_height = h;
    if(f!=null)google_ad_format = f;
    if(t!=null)google_ad_type = t;
    if(ch!=null)google_ad_channel = ch;
    if(c1!=null)google_color_border = c1;
    if(c2!=null)google_color_bg = c2;
    if(c3!=null)google_color_link = c3;
    if(c4!=null)google_color_text = c4;
    if(c5!=null)google_color_url = c5;
}
function ReLoadGoogle(id,w,h,f,t,ch,c1,c2,c3,c4,c5)
{
    CreateGoogle(w,h,f,t,ch,c1,c2,c3,c4,c5);
    obj = document.getElementById(id);
    if(obj!=null)
    {
        obj.src = "http://pagead2.googlesyndication.com/pagead/show_ads.js?t="+Math.random()*100000;
    }
}

function NeatDialog(sHTML, sTitle, bCancel,width)
{
  window.neatDialog = null;
  this.elt = null;
  if (document.createElement  &&  document.getElementById)
  {
    var dg = document.createElement("div");
    dg.className = "neat-dialog";
	dg.style.width = width+"px";
    dg.innerHTML = sHTML;

    var dbg = document.createElement("div");
    dbg.id = "nd-bdg";
    dbg.className = "neat-dialog-bg";

    var dgc = document.createElement("div");
    dgc.className = "neat-dialog-cont";
    dgc.appendChild(dbg);
    dgc.appendChild(dg);

    if (document.body.offsetLeft > 0)
      dgc.style.marginLeft = document.body.offsetLeft + "px";

    document.body.appendChild(dgc);
    if (bCancel) document.getElementById("nd-cancel").onclick = function()
    {
      window.neatDialog.close();
    };
    this.elt = dgc;
    window.neatDialog = this;
  }
}
NeatDialog.prototype.close = function()
{
  if (this.elt)
  {
    this.elt.style.display = "none";
    this.elt.parentNode.removeChild(this.elt);
  }
  window.neatDialog = null;
}

function openDiv(url,title,clstxt,width,height)
{
    var sHTML = '<div class="neat-dialog-titlebg" style="width:'+width+'px;"><span class=pop_left style="margin:5px 5px 0px 5px">'+unescape(title)+'</span><span class=pop_right style="width:18px;height:25px;padding-top:10px; margin-right:10px" onclick="parent.window.neatDialog.close()" ><a href=javascript:void(0) onmouseout=MM_swapImgRestore() onmouseover=MM_swapImage("Image2","","/Images/icon_pop_close2.gif",1)><img src=/Images/icon_pop_close.gif title="'+clstxt+'"  border="0" name="Image2" border="0" id="Image2"  /></a></span></div><iframe scrolling="auto" frameborder="0" marginheight="0" marginwidth="0" width="'+width+'" height="'+height+'" src="'+url+'"><button onclick="window.neatDialog.close()">'+clstxt+'</button>';
    new NeatDialog(sHTML, "italki.com", false,width);
}

function AddValidHandler(arrList,button,func)
{
    for(var i=0;i<arrList.length;i++)
    {
        var vobj = arrList[i];
        if(vobj.elt&&vobj.evn&&vobj.elt1&&vobj.msg)
        {
            $addHandler(vobj.elt,vobj.evn,Valid);
            arrList[i].elt.arr = arrList;
            vobj.elt1.innerHTML = vobj.msg;
        }
        else
        {
            continue;
        }
    }
    button.callFunc = func;
    button.arr = arrList;
    $addHandler(button,"click",Valid);
}

function Valid(eventElement)
{
    var flag = ValidHandler(eventElement.target.arr);
    if(flag&&eventElement.target.callFunc)
    {
        eventElement.target.callFunc();
    }
}

function ValidHandler(arrList)
{
    var focusObj = null;
    for(var i=0;i<arrList.length;i++)
    {
        var vobj = arrList[i];
        if(vobj.elt&&vobj.elt1&&vobj.reg&&vobj.msg&&vobj.evn)
        {
            if(!RegularValid(vobj.elt,vobj.reg))
            {
                //Sys.UI.DomElement.setVisible(vobj.elt1, true);
                show(vobj.elt1, true);
                Sys.UI.DomElement.addCssClass(vobj.elt, "validatorCalloutHighlight");
                if(focusObj==null) focusObj=vobj.elt;
            }
            else
            {
                //Sys.UI.DomElement.setVisible(vobj.elt1, false);
                show(vobj.elt1, false);
                Sys.UI.DomElement.removeCssClass(vobj.elt, "validatorCalloutHighlight");
            }
        }
        else
        {
            continue;
        }
    }
    if(focusObj!=null) focusObj.focus();
    return focusObj==null;
}

function RegularValid(control,reg) 
{
    var value = __ValidatorGetValue(control);
    var rx = new RegExp(reg);
    var matches = rx.exec(value);
    return (matches != null && value == matches[0]);
}

function __ValidatorGetValue(control) {
    if (typeof(control.value) == "string") {
        return control.value;
    }
    return __ValidatorGetValueRecursive(control);
}
function __ValidatorGetValueRecursive(control)
{
    if (typeof(control.value) == "string" && (control.type != "radio" || control.checked == true)) {
        return control.value;
    }
    var i, val;
    for (i = 0; i<control.childNodes.length; i++) {
        val = __ValidatorGetValueRecursive(control.childNodes[i]);
        if (val != "") return val;
    }
    return "";
}

function GetVisible(e) 
{
    if (!e) return false;
    return (("none" != GetCurrentStyle(e, "display")) && ("hidden" != GetCurrentStyle(e, "visibility")));
}
function GetCurrentStyle(element, attribute, defaultValue) 
{
    var currentValue = null;
    if (element) 
    {
        if (element.currentStyle) 
        {
            currentValue = element.currentStyle[attribute];
        } 
        else if (document.defaultView && document.defaultView.getComputedStyle) 
        {
            var style = document.defaultView.getComputedStyle(element, null);
            if (style) 
            {
                currentValue = style[attribute];
            }
        }
        
        if (!currentValue && element.style.getPropertyValue) 
        {
            currentValue = element.style.getPropertyValue(attribute);
        }
        else if (!currentValue && element.style.getAttribute) 
        {
            currentValue = element.style.getAttribute(attribute);
        }       
    }
    
    if ((!currentValue || currentValue == "" || typeof(currentValue) === 'undefined'))
    {
        if (typeof(defaultValue) != 'undefined') 
        {
            currentValue = defaultValue;
        }
        else 
        {
            currentValue = null;
        }
    }   
    return currentValue;  
}

function ApplyProperties(target, properties) 
{
    for (var p in properties) 
    {
        var pv = properties[p];
        if (pv != null && Object.getType(pv)===Object) 
        {
            var tv = target[p];
            ApplyProperties(tv, pv);
        } 
        else 
        {
            target[p] = pv;
        }
    }
}

function SetStyle(element, style) 
{
    ApplyProperties(element.style, style);
}

function GetString(str,len,strReplace)
{
     var strlen = 0;
     var s = "";
    for(var i = 0;i < str.length;i++)
    {
            if(str.charCodeAt(i) > 128)
             strlen += 2;
            else
            strlen++;
            s += str.charAt(i);
            if(strlen >= len)
            {
                if(strReplace)
                {
                    s = s + strReplace;
                }
                else
                {
                    s = s+"...";
                }
                return s;
            }
    }
    return s;
}
function EncodeMessage(str)
{
    str = str.replace(/\t/gi,"&nbsp;&nbsp;&nbsp;").replace(/\n/gi,"<br/>");
    return str;
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->